package com.zeng.sim.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeng.sim.controller.domain.SysDictType;
import com.zeng.sim.controller.domain.request.PageDomain;
import com.zeng.sim.controller.domain.response.Result;
import com.zeng.sim.controller.domain.response.ResultTable;
import com.zeng.sim.service.SysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zengwanlin
 * @since 2023-12-20
 */
@Controller
@RequestMapping("/sys/dictType")
public class SysDictTypeController {

    @Autowired
    private SysDictTypeService sysDictTypeService;

    @GetMapping("/main")
    public String main() {
        return "system/dict/main";
    }

    @GetMapping("/add")
    public String add() {
        return "system/dict/add";
    }

    @GetMapping("/edit")
    public String edit(Model model, Integer dictTypeId) {
        model.addAttribute("sysDictType", sysDictTypeService.getById(dictTypeId));
        return "system/dict/edit";
    }

    @GetMapping("/data")
    @ResponseBody
    public ResultTable data(SysDictType sysDictType, PageDomain pageDomain) {
        Page<SysDictType> page = sysDictTypeService.pageQuery(sysDictType, pageDomain);
        return ResultTable.pageTable(page);
    }

    @PostMapping("/save")
    @ResponseBody
    public Result save(@RequestBody SysDictType dictType) {
        sysDictTypeService.saveSysDictType(dictType);
        return Result.success();
    }

    @PutMapping("/update")
    @ResponseBody
    public Result update(@RequestBody SysDictType dictType) {
        sysDictTypeService.updateSysDictType(dictType);
        return Result.success();
    }

    @DeleteMapping("/remove/{id}")
    @ResponseBody
    public Result remove(@PathVariable Integer id) {
        return Result.decide(sysDictTypeService.removeById(id));
    }

    @DeleteMapping("/batchRemove/{ids}")
    @ResponseBody
    public Result batchRemove(@PathVariable String ids) {
        return Result.decide(sysDictTypeService.batchRemove(ids));
    }

    @PutMapping("/valid/{id}")
    @ResponseBody
    public Result valid(@PathVariable Integer id) {
        return Result.decide(sysDictTypeService.valid(id));
    }

    @PutMapping("/invalid/{id}")
    @ResponseBody
    public Result invalid(@PathVariable Integer id) {
        return Result.decide(sysDictTypeService.invalid(id));
    }

}
